﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Xml.Serialization;
using System.IO;
using System.Globalization;
using System.Resources;
using System.Net;
using System.Reflection;

namespace WLS
{
    public partial class setting : Form
    {
        int zmen = 2;
        int indexs = 0;
        all_setting p;
        string version, new_version;
        About fr1;
        string reset = "",warning="";
        public setting(all_setting p_, ref all_setting _jazyk)
        {
            InitializeComponent();
            p = p_;
            p = _jazyk;
            p.JazykZmenen += new all_setting.ZmenaJazyku(jazyk_JazykZmenen);
            jazyk_JazykZmenen(p.jazyk);
            if (p.jazyk == "en-US")
                comboBox1.SelectedItem = comboBox1.Items[0];
            else
                comboBox1.SelectedItem = comboBox1.Items[1]; // blbe reseni
        }

        /// <summary>
        /// Změní jazyk
        /// </summary>
        /// <param name="jazyk"></param>
        void jazyk_JazykZmenen(string jazyk)
        {
            CultureInfo cultura = CultureInfo.CreateSpecificCulture(jazyk);
            ResourceManager manager = new ResourceManager("WLS.Res", typeof(setting).Assembly);
            label1.Text = manager.GetString("accountid", cultura);
            label2.Text = manager.GetString("accountkey", cultura);
            label3.Text = manager.GetString("accountid", cultura);
            label4.Text = manager.GetString("accountkey", cultura);
            label6.Text = manager.GetString("helpdesk", cultura);
            label7.Text = manager.GetString("Methodofdisposal", cultura);
            label8.Text = manager.GetString("Warning", cultura);
            warning=manager.GetString("Warning", cultura);
            label9.Text = manager.GetString("PublicV", cultura);
            checkBox1.Text = manager.GetString("autodelete", cultura);
            checkBox2.Text = manager.GetString("warningmessages", cultura);
            checkBox3.Text = manager.GetString("encryptpassservers", cultura);
            linkLabel1.Text = manager.GetString("registration", cultura);
            linkLabel2.Text = manager.GetString("youtube", cultura);
            linkLabel3.Text = manager.GetString("registration", cultura);
            linkLabel4.Text = manager.GetString("silverlight", cultura);
            tabPage1.Text = manager.GetString("account", cultura);
            label5.Text = manager.GetString("languages", cultura);
            tabPage2.Text = manager.GetString("language", cultura);
            linkLabel5.Text = manager.GetString("pageonourwebsite", cultura);
            tabPage4.Text = manager.GetString("help", cultura);
            comboBox1.Items[0] = (manager.GetString("english", cultura));
            comboBox1.Items[1] = (manager.GetString("cestina", cultura));
            this.Text = manager.GetString("settingmain", cultura);
            version = manager.GetString("version", cultura);
            new_version = manager.GetString("version", cultura);
            loglanguage = manager.GetString("loglanguage", cultura);
            checkBox2.Text = manager.GetString("hlasky", cultura);
            menuItem1.Text = manager.GetString("possibilities", cultura);
            menuItem6.Text = manager.GetString("autors", cultura);
            menuItem2.Text = manager.GetString("akutalizace", cultura);
            menuItem7.Text = manager.GetString("resetsettings", cultura);
            menuItem5.Text = manager.GetString("back", cultura);
            menuItem4.Text = manager.GetString("savesett", cultura);
            messagebox1 = manager.GetString("messagebox1", cultura);
            messagebox2 = manager.GetString("messagebox2", cultura);
            reset = manager.GetString("reset", cultura);
            label10.Text = manager.GetString("sharetab", cultura);
            label11.Text = manager.GetString("sharetab2", cultura);
            linkLabel6.Text = manager.GetString("linkshare", cultura);
            tabControl2.TabPages[2].Text = manager.GetString("tabsharetext", cultura);
        }
        string messagebox1;
        string messagebox2;
        string loglanguage;
        private void setting_Load(object sender, EventArgs e)
        {
            if (this.Tag != null) p = (all_setting)this.Tag;
            textBox1.Text = p.sl_ac;
            textBox2.Text = p.sl_pass;
            textBox3.Text = p.yt_ac;
            textBox4.Text = p.yt_pass;
            textBox5.Text = p.log;
            checkBox1.Checked = p.delete_video;
            checkBox3.Checked = p.encrypt_pass;
            checkBox2.Checked = p.up_messages;
        }


        private void linkLabel5_Click(object sender, EventArgs e)
        {
            DialogResult result = MessageBox.Show(messagebox1, messagebox2, MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1);
            if (result == DialogResult.Yes)
            {
                System.Diagnostics.Process.Start("http://www.codeplex.com/wmstream", "");
            }
        }

        private void tabPage3_Paint(object sender, PaintEventArgs e)
        {
            textBox5.Text = p.log;
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if ((comboBox1.Text == "Angličtina" || comboBox1.Text == "English") && zmen == 0)
            {
                indexs = comboBox1.SelectedIndex;
                zmen++;
                p.jazyk = "en-US";
                p.log = loglanguage + "en-US" + Environment.NewLine + p.log;
            }
            else if ((comboBox1.Text == "Čeština" || comboBox1.Text == "Czech") && zmen == 0)
            {
                indexs = comboBox1.SelectedIndex;
                zmen++;
                p.jazyk = "cs-CZ";
                p.log = loglanguage + "cs-CZ" + Environment.NewLine + p.log;
            }
            if (zmen == 1)
            {
                comboBox1.SelectedItem = comboBox1.Items[indexs];
                zmen++;
            }
            zmen = 0;
        }

        private void menuItem2_Click(object sender, EventArgs e)
        {
            if (p.up_messages == true)
            {
                DialogResult result = MessageBox.Show(messagebox1, messagebox2, MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1);
                if (result == DialogResult.Yes)
                {

                    checkversion();
                }
            }
            else
                checkversion();
        }

        private void checkversion()
        {

            try
            {
                HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://fczbk.cz/wls/akt.html");
                request.KeepAlive = true;
                request.ContentType = @"application/x-www-form-urlencoded";
                HttpWebResponse response = (HttpWebResponse)request.GetResponse();
                StreamReader read = new StreamReader(response.GetResponseStream());
                string version = read.ReadToEnd();
                response.Close();
                if (Assembly.GetExecutingAssembly().GetName().Version.ToString() != version)
                {
                    MessageBox.Show(new_version + ": " + Assembly.GetExecutingAssembly().GetName().Version.ToString());
                }
                else
                    MessageBox.Show(version);
            }
            catch { }
        }

        private void menuItem3_Click(object sender, EventArgs e)
        {
            if (p.up_messages == true)
            {
                DialogResult result = MessageBox.Show(messagebox1, messagebox2, MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1);
                if (result == DialogResult.Yes)
                {
                    System.Diagnostics.Process.Start("http://www.codeplex.com/wmstream", "");
                }
            }
            else
                System.Diagnostics.Process.Start("http://www.codeplex.com/wmstream", "");
        }

        private void menuItem4_Click(object sender, EventArgs e)
        {
            p.sl_ac = textBox1.Text;
            p.sl_pass = textBox2.Text;
            p.yt_ac = textBox3.Text;
            p.yt_pass = textBox4.Text;
            p.up_messages = checkBox2.Checked;
            p.encrypt_pass = checkBox3.Checked;
            p.delete_video = checkBox1.Checked;
            this.Close();
        }

        private void menuItem5_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void menuItem7_Click(object sender, EventArgs e)
        {
            DialogResult r = MessageBox.Show(reset, warning, MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1);
            if (r == DialogResult.Yes)
            {
                textBox1.Text = "";
                textBox2.Text = "";
                textBox3.Text = "";
                textBox4.Text = "";
                textBox5.Text = "";
                checkBox1.Checked = true;
                checkBox2.Checked = true;
                checkBox3.Checked = true;
                comboBox1.SelectedItem = comboBox1.Items[0];
                this.Close();
            }
        }

        private void menuItem6_Click(object sender, EventArgs e)
        {
            if (fr1 == null) fr1 = new About(ref p);
            fr1.ShowDialog();
        }

        private void linkLabel3_Click_1(object sender, EventArgs e)
        {
            if (p.up_messages == true)
            {
                DialogResult result = MessageBox.Show(messagebox1, messagebox2, MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1);
                if (result == DialogResult.Yes)
                {
                    System.Diagnostics.Process.Start("http://login.live.com/login.srf", "");
                }
            }
            else
                System.Diagnostics.Process.Start("http://login.live.com/login.srf", "");
        }

        private void linkLabel4_Click(object sender, EventArgs e)
        {
            if (p.up_messages == true)
            {
                DialogResult result = MessageBox.Show(messagebox1, messagebox2, MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1);
                if (result == DialogResult.Yes)
                {
                    System.Diagnostics.Process.Start("http://silverlight.live.com/", "");
                }
            }
            else
                System.Diagnostics.Process.Start("http://login.live.com/login.srf", "");
        }

        private void linkLabel2_Click(object sender, EventArgs e)
        {
            if (p.up_messages == true)
            {
                DialogResult result = MessageBox.Show(messagebox1, messagebox2, MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1);
                if (result == DialogResult.Yes)
                {
                    System.Diagnostics.Process.Start("http://www.youtube.com/", "");
                }
            }
            else
                System.Diagnostics.Process.Start("http://www.youtube.com/", "");
        }

        private void linkLabel1_Click_1(object sender, EventArgs e)
        {
            if (p.up_messages == true)
            {
                DialogResult result = MessageBox.Show(messagebox1, messagebox2, MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1);
                if (result == DialogResult.Yes)
                {
                    System.Diagnostics.Process.Start("http://www.youtube.com/create_account/", "");
                }
            }
            else
                System.Diagnostics.Process.Start("http://www.youtube.com/create_account/", "");
        }

        private void linkLabel6_Click(object sender, EventArgs e)
        {
            if (p.up_messages == true)
            {
                DialogResult result = MessageBox.Show(messagebox1, messagebox2, MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1);
                if (result == DialogResult.Yes)
                {
                    System.Diagnostics.Process.Start("http://www.youtube.com/account#sharing/activity", "");
                }
            }
            else
                System.Diagnostics.Process.Start("http://www.youtube.com/account#sharing/activity", "");
        }
    }
}